<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'base.item.class.php');

class CoreBannedBase extends BaseItemBase {
	
	//constructor
	function CoreBannedBase() {
		parent::BaseItemBase();
		
		$this->table = 'pp_banned';
		$this->prefix = 'banned_';
	}
	
	//methods
	function checkCurrentBanned() {
		$ip = util_get_ip_address();
		$ips = explode('.', $ip);
		if( sizeof($ips) != 4 ) {
			return false;	
		}
		$ip1 = $ips['0'];
		$ip2 = $ips['1'];
		$ip3 = $ips['2'];
		$ip4 = $ips['3'];
		
		$check = $this->_check_ip_banned($ip1, $ip2, $ip3, $ip4);
		if( $check == true ) {
			return true;	
		}
		
		return false;
	}
	
	//private
	function _check_ip_banned($ip1, $ip2, $ip3, $ip4) {
		$query = "select count(*) as count from " . $this->table . " where banned_expiration < now() " 
				. " and (banned_ip1 = 0 or banned_ip1 = '" . $ip1 . "') " 
				. " and (banned_ip2 = 0 or banned_ip2 = '" . $ip2 . "') " 
				. " and (banned_ip3 = 0 or banned_ip3 = '" . $ip3 . "') " 
				. " and (banned_ip4 = 0 or banned_ip4 = '" . $ip4 . "') " 
				;
		
		return $this->adb->checkCount($query);
	}
}
//
?>